Answer the following questions and complete the exercises in
RMarkdown. Please embed all of your code and push your final work to
your repository. Your final lab report should be organized, clean, and
run free from errors. Remember, you must remove the # for
the included code chunks to run. Be sure to add your name to the author
header above. For any included plots, make sure they are clearly
labeled. You are free to use any plot type that you feel best
communicates the results of your analysis.
Make sure to use the formatting conventions of RMarkdown to make your report neat and clean!
library(tidyverse)
library(janitor)
library(ggmap)
register_stadiamaps("4bb3569f-aecd-42d8-9721-de9f3992e630", write = FALSE)
We will use two separate data sets for this homework.
The first data set represent sightings of grizzly bears (Ursos arctos) in Alaska.
The second data set is from Brandell, Ellen E (2021), Serological dataset and R code for: Patterns and processes of pathogen exposure in gray wolves across North America, Dryad, Dataset.
Load the grizzly data and evaluate its
structure.
grizzly <- read_csv("data/bear-sightings.csv") %>% clean_names()
## Rows: 494 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (3): bear.id, longitude, latitude
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
str(grizzly)
## spc_tbl_ [494 × 3] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
## $ bear_id : num [1:494] 7 57 69 75 104 108 115 116 125 135 ...
## $ longitude: num [1:494] -149 -153 -145 -153 -143 ...
## $ latitude : num [1:494] 62.7 58.4 62.4 59.9 61.1 ...
## - attr(*, "spec")=
## .. cols(
## .. bear.id = col_double(),
## .. longitude = col_double(),
## .. latitude = col_double()
## .. )
## - attr(*, "problems")=<externalptr>
grizzly %>%
select(latitude, longitude) %>%
summary()
## latitude longitude
## Min. :55.02 Min. :-166.2
## 1st Qu.:58.13 1st Qu.:-154.2
## Median :60.97 Median :-151.0
## Mean :61.41 Mean :-149.1
## 3rd Qu.:64.13 3rd Qu.:-145.6
## Max. :70.37 Max. :-131.3
lat <- c(55.02, 70.37)
long <- c(-166.2, -131.3)
bbox <- make_bbox(long, lat, f = 0.03)
stamen in a terrain style projection
and display the map.map1 <- get_stadiamap(bbox, maptype = "stamen_terrain", zoom=5)
## ℹ © Stadia Maps © Stamen Design © OpenMapTiles © OpenStreetMap contributors.
ggmap(map1)
ggmap(map1) +
geom_point(data = grizzly, aes(longitude, latitude), size=0.4) +
labs(x= "Longitude", y= "Latitude", title="Grizzly Bear Sightings")
Let’s switch to the wolves data. Brandell, Ellen E (2021), Serological dataset and R code for: Patterns and processes of pathogen exposure in gray wolves across North America, Dryad, Dataset.
wolves <- read_csv("data/wolves_data/wolves_dataset.csv") %>% clean_names()
## Rows: 1986 Columns: 23
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): pop, age.cat, sex, color
## dbl (19): year, lat, long, habitat, human, pop.density, pack.size, standard....
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
glimpse(wolves)
## Rows: 1,986
## Columns: 23
## $ pop <chr> "AK.PEN", "AK.PEN", "AK.PEN", "AK.PEN", "AK.PEN", "…
## $ year <dbl> 2006, 2006, 2006, 2006, 2006, 2006, 2006, 2006, 200…
## $ age_cat <chr> "S", "S", "A", "S", "A", "A", "A", "P", "S", "P", "…
## $ sex <chr> "F", "M", "F", "M", "M", "M", "F", "M", "F", "M", "…
## $ color <chr> "G", "G", "G", "B", "B", "G", "G", "G", "G", "G", "…
## $ lat <dbl> 57.03983, 57.03983, 57.03983, 57.03983, 57.03983, 5…
## $ long <dbl> -157.8427, -157.8427, -157.8427, -157.8427, -157.84…
## $ habitat <dbl> 254.08, 254.08, 254.08, 254.08, 254.08, 254.08, 254…
## $ human <dbl> 10.42, 10.42, 10.42, 10.42, 10.42, 10.42, 10.42, 10…
## $ pop_density <dbl> 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, …
## $ pack_size <dbl> 8.78, 8.78, 8.78, 8.78, 8.78, 8.78, 8.78, 8.78, 8.7…
## $ standard_habitat <dbl> -1.6339, -1.6339, -1.6339, -1.6339, -1.6339, -1.633…
## $ standard_human <dbl> -0.9784, -0.9784, -0.9784, -0.9784, -0.9784, -0.978…
## $ standard_pop <dbl> -0.6827, -0.6827, -0.6827, -0.6827, -0.6827, -0.682…
## $ standard_packsize <dbl> 1.3157, 1.3157, 1.3157, 1.3157, 1.3157, 1.3157, 1.3…
## $ standard_latitude <dbl> 0.7214, 0.7214, 0.7214, 0.7214, 0.7214, 0.7214, 0.7…
## $ standard_longitude <dbl> -2.1441, -2.1441, -2.1441, -2.1441, -2.1441, -2.144…
## $ cav_binary <dbl> 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …
## $ cdv_binary <dbl> 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ cpv_binary <dbl> 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, …
## $ chv_binary <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, …
## $ neo_binary <dbl> NA, NA, NA, 0, 0, NA, NA, 1, 0, 1, NA, 0, NA, NA, N…
## $ toxo_binary <dbl> NA, NA, NA, 1, 0, NA, NA, 1, 0, 0, NA, 0, NA, NA, N…
wolves_48_states <- wolves %>%
distinct(pop, .keep_all = TRUE)
wolves_48_states %>%
select(lat, long) %>%
summary()
## lat long
## Min. :33.89 Min. :-157.84
## 1st Qu.:46.83 1st Qu.:-131.10
## Median :55.82 Median :-111.11
## Mean :54.99 Mean :-116.78
## 3rd Qu.:63.29 3rd Qu.:-109.17
## Max. :80.50 Max. : -82.42
lat <- c(33.89, 80.50)
long <- c(-157.84, -82.42)
bbox2 <- make_bbox(long, lat, f = 0.03)
stamen in a terrain-lines
projection and display the map.map2 <- get_stadiamap(bbox2, maptype = "stamen_terrain", zoom=4)
## ℹ © Stadia Maps © Stamen Design © OpenMapTiles © OpenStreetMap contributors.
ggmap(map2)
ggmap(map2) +
geom_point(data = wolves_48_states, aes(long, lat), size=0.4) +
labs(x= "Longitude", y= "Latitude", title="Pathogen Exposure in Gray Wolves")
fill and color by population.ggmap(map2) +
geom_point(data = wolves_48_states, aes(long, lat, fill=pop, color=pop), size=1) +
labs(x= "Longitude", y= "Latitude", title="Pathogen Exposure in Gray Wolves")
Please be sure that you check the keep md file in the
knit preferences.